import * as types from '../types';
import * as helps from '@/utils/helps';
import { cloneDeep } from '@ktw/ktools';
import queryManager from '../../utils/query-manager';

/**
 * 查询分析
 */
const query = {
  state: {
    // 存储系统查询属性信息对象
    attribute: [],
  },
  getters: {
    attribute: state => queryManager.getQueryOptions(state.attribute),
  },
  mutations: {
    // 添加属性表查询对象信息
    [types.SET_BUS_ATTRIBUTE](
      state,
      { options, queryOptions = options, attributeType = 'wfsQuery' }
    ) {
      if (attributeType === 'wfsQuery' && !options.url) throw new Error('wfs查询参数 url 缺失');
      const deepOptions = cloneDeep(options);
      deepOptions.options = queryOptions;
      deepOptions.attributeType = attributeType;
      queryManager.setQueryOptions([deepOptions]);
      state.attribute = [{ options, attributeType }];
    },
  },
};

export default query;
